package vn.com.ltv.lo.adapter;

import java.util.ArrayList;

import vn.com.ltv.lo.R;
import vn.com.ltv.lo.common.ImageDishObject;
import android.app.Activity;
import android.content.res.TypedArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.three20.ui.TTImageView;

public class GViewAdapter extends BaseAdapter
{
    private Activity activity;
    private int itemBackground;
    ArrayList<ImageDishObject> listImage = new ArrayList<ImageDishObject>();

	public GViewAdapter(Activity activity, ArrayList<ImageDishObject> listImage) 
    {
        this.activity = activity;
        //---setting the style---
        TypedArray a = activity.obtainStyledAttributes(R.styleable.Gallery);
        itemBackground = a.getResourceId(
            R.styleable.Gallery_android_galleryItemBackground, 0);
        a.recycle();    
        this.listImage.addAll(listImage);
    }
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listImage.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public static class ViewHolder
	{
		public TTImageView imgViewFlag;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder view;
		LayoutInflater inflator = activity.getLayoutInflater();
		
		if(convertView==null)
		{
			view = new ViewHolder();
			convertView = inflator.inflate(R.layout.gallery_row, null);
			
			view.imgViewFlag = (TTImageView) convertView.findViewById(R.id.gallery_row_img);
			
			convertView.setTag(view);
		}
		else
		{
			view = (ViewHolder) convertView.getTag();
		}
		
		view.imgViewFlag.setImageURL(listImage.get(position).getPath());
		
		return convertView;
	}

}
